package JZOffer;

// https://leetcode.cn/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/
// 连续子数组的最大和
public class Day009_1 {
    public int maxSubArray(int[] nums) {
        int min = 0;
        int ans = Integer.MIN_VALUE;
        int n = 0;
        for (int num : nums) {
            n += num;
            ans = Math.max(n - min, ans);
            if (min > n) {
                min = n;
            }
        }
        return ans;
    }
}
